################################################################
#
# This script library provides for the Machine based functions
#
################################################################

function Get-KCMDMachine {
	<#
	.Synopsis
		Gets a list of machines from Kaseya.
	.Description
		Gets a list of machines from Kaseya.

	.Parameter Machine
		Used to specify the name of a specific machine.
	.Parameter Group
		Used to query only machines in a specific group.
	.Parameter IpAddress
		Use to query a specific machine by IP.

	.Example
		# Query for all machines in Kaseya
		Get-KCMDMachine
		
	.Example
		# Get a list of machines in a specific group
		Get-KCMDMachine -Group group.root
		
	.Example
		# Get a specific machine by name
		Get-KCMDMachine -Machine mymachine
	#>
	
	[CmdletBinding()]
	param(
		[Parameter()]
		[string]$Group,
		[Parameter()]
		[string]$Machine,
		[Parameter()]
		[string]$IpAddress,
		[Parameter()]
		[string]$SessionID = $KaseyaSessionID
	)

	$KaseyaMachineRequest = New-Object KaseyaWS.GetMachineListRequest
	$KaseyaMachineRequest.SessionID = $SessionID
	
	if($Group){
		$KaseyaMachineRequest.MachineGroup = $Group
	}
	
	$KaseyaMachineListReq = $KaseyaInst.GetMachineList($KaseyaMachineRequest)
	if($KaseyaMachineListReq.ErrorMessage){
		Write-Error -Message $KaseyaMachineListReq.ErrorMessage
		break;
	}
	
	$KaseyaMachineList = $KaseyaMachineListReq.Machines
	
	if($Machine){
		$MachineGroupID = $KaseyaMachineList | Where-Object{ $_.Machine_GroupID -match "$Machine\." }
		
	}

}
